var app = getApp()

Page({
  data: {
    
  },
  onLoad:function(e){
    var that = this
    let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
    this.setData({
      token: extConfig.appid
    })
      wx.request({
        url: 'https://www.58zltc.com/api.php/Index?token=' + that.data.token + '&pageNum=' + that.data.pageNum ,
        success: res => {
          that.setData({
            list: res.data.wechat
          })
          wx.hideLoading();
        }
      })
  },
  getuserinfo:function(e){
    console.log(e)
    var user = e.detail.userInfo;
    if(user){
      app.globalData.userInfo = user;
      console.log(user)
      this.setuser();
    }else{
      wx.showToast({
        icon:'none',
        title: '授权失败，请重新授权',
      })
    }
    
  },
  setuser: function () {
    // 获取用户信息
    let that = this;
    var arr = { openid: app.globalData.openid}
    app.ihttpPost('https://www.58zltc.com/api.php/Index/user/openid/' + app.globalData.openid, app.globalData.userInfo, function (res) {
      setTimeout(function () {
        wx.switchTab({
          url: '../index',
        })
      }, 1500)
      wx.setStorage({
        key: 'openid',
        data: res.data.openid,
      })
      wx.showToast({
        title: '授权成功！'
      })
      
    })
  },
});